﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Cosmetic.Logic;
using System.Collections.Generic;
using Cosmetic.DataEntity;
using System.Data.SqlClient;
namespace WebApp.Controls
{
    public partial class ShowCategoryList_Ls : System.Web.UI.UserControl
    {
        private CategoryManager m_CategoryManager = new CategoryManager();
        public bool SubCategoryVisible
        {
            set
            {

            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Category theProductTopCategory = m_CategoryManager.GetTopCategryByName(CategoryManager.ETopCategory.Category_L);
                this.rptMainCategory.DataSource = m_CategoryManager.GetSubCateogoriesBySupCategory(theProductTopCategory).OrderBy(theCategory => theCategory.Index);
                this.rptMainCategory.DataBind();
            }
        }

        protected void rptMainCategory_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {

            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Repeater theRptCategory = (Repeater)e.Item.FindControl("rptSubCategory");
                Category theSupCategory = e.Item.DataItem as Category;

                theRptCategory.DataSource = this.m_CategoryManager.GetSubCateogoriesBySupCategory(theSupCategory).OrderBy(theCategory => theCategory.Index);
                theRptCategory.DataBind();
            }
        }

        protected void LinkButton_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Product/SearchProductNew.aspx?price=" + ((LinkButton)sender).CommandArgument);
        }
        public DataTable GenerateTab()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("PriceBelow", typeof(System.String));
            dt.Columns.Add("PriceTop", typeof(System.String));

            string str = System.Configuration.ConfigurationManager.AppSettings["PriceSelect"].ToString();
            string[] strItem = str.Split(new char[] { '|' }); //第一个数小，第二个数大。例：10，20
            for (int i = 0; i < strItem.Length; i++)
            {
                string[] strPrice = strItem[i].Split(new char[] { ',' });
                DataRow dr = dt.NewRow();
                dr[0] = strPrice[0];
                dr[1] = strPrice[1];
                dt.Rows.Add(dr);
            }

            return dt;
        }

    }//end class
}